package com.mayihr.fx.attributeBind.TableViewWithAddButtonExample;

import javafx.beans.value.ObservableValue;
import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.util.Callback;

import javax.swing.text.TableView;

public class TableCellImpl extends TableCell<Person, String> {

    private Label textField=new Label();

    private Button button = new Button("...");

    private HBox vBox = new HBox();
    private StackPane stackPane = new StackPane();

    TableCellImpl(){
//        super();
//        textField.setText(((Person) this.getTableRow().getTableView().getItems().get(getIndex())).getInfo());
        textField.setPrefWidth(USE_COMPUTED_SIZE);
        vBox.setAlignment(Pos.CENTER_RIGHT);
        vBox.getChildren().addAll(textField, button);
        stackPane.getChildren().add(vBox);
        button.setOnAction(event -> {
            System.out.println(textField.getText());
        });
    }

    public void updateItem(String item, boolean empty) {
        super.updateItem(item, empty);
        if (!empty) {
            Person person=getTableColumn().getTableView().getItems().get(getIndex());
            textField.setText(person.getInfo());
            setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
            setGraphic(stackPane);
        } else {
            setGraphic(null);
        }
    }


}
